package first.progr.tc;

import static first.progr.tc.GroupDataGenerator.loadGroupsFromXmlFile;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import first.progr.utils.SortedListOf;

public class GroupCreationTests extends TestBase{
	
  @DataProvider
  public Iterator<Object[]> groupsFromFile() throws IOException {
	 return wrapGroupsForDataProvider(loadGroupsFromXmlFile(new File("groups.xml"))).iterator();    
  }
	
  @Test(dataProvider = "groupsFromFile")
  public void testGroupCreatingWithValidData(GroupData gr) throws Exception {
    //Save old groups state
    SortedListOf<GroupData> oldGroupsList = app.getGroupHelper().getGroups();
      
    //Actions
    app.getGroupHelper().createGroup(gr);
    
    //Save new groups state
    SortedListOf<GroupData> newGroupsList = app.getGroupHelper().getGroups();
    
    //Compare states of lists 
    assertThat(newGroupsList, equalTo(oldGroupsList.withAdded(gr)));
  }
}
